package com.hmdp.entity.result;

import cn.hutool.http.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 统一响应结果类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    // 成功标识
    private Boolean status;
    // 响应状态码
    private Integer code;
    // 响应信息
    private String message;
    // 响应数据
    private Object data;
    // 响应总数
    private Long total;

    public static Result ok() {
        return new Result(true, HttpStatus.HTTP_OK,null, null, null);
    }

    public static Result ok(Object data) {
        return new Result(true, HttpStatus.HTTP_OK, null, data, null);
    }

    public static Result ok(Object data, String msg) {
        return new Result(true, HttpStatus.HTTP_OK, msg, data, null);
    }

    public static Result ok(List<?> data, Long total) {
        return new Result(true, HttpStatus.HTTP_INTERNAL_ERROR, null, data, total);
    }

    public static Result fail() {
        return new Result(false, HttpStatus.HTTP_INTERNAL_ERROR, null, null, null);
    }

    public static Result fail(String msg) {
        return new Result(false, HttpStatus.HTTP_INTERNAL_ERROR, msg, null, null);
    }
}
